import App from './App'
import wybButton from '@/components/wyb-button/wyb-button.vue'
import http from '@/common/js/http/'
// #ifndef VUE3
import Vue from 'vue'
Vue.component('wyb-button',wybButton)
Vue.config.productionTip = false
App.mpType = 'app'
Vue.prototype.$http = http
http.config.baseUrl = "http://192.168.0.115:88"
http.interceptor.request = (config) => {
  console.log("==========请求拦截器==========");
  // 对于登录路径不携带token
  if (config.url == 'http://192.168.0.115:88/api/user/login') {
    console.log("当前路径为登录：不携带token");
  }else {
    var token = uni.getStorageSync('token');
    config.header = {
      "token": token
    }
  }
  console.log("==========请求拦截器==========");
}
http.interceptor.response = (response) => {
  console.log("==========响应拦截器==========");
  if(response.data.code == 444) {
    // 清除token信息
    uni.removeStorageSync('token');
    // token过期跳转到登录界面
    uni.redirectTo({
      url: '/pages/login/Login'
    })
  }
  console.log("==========响应拦截器==========");
  return response;
}

const app = new Vue({
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif